//
//  LivingController.m
//  BigToBig
//
//  Created by guochuangkeshi on 16/4/22.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "LivingController.h"
#import <AVFoundation/AVFoundation.h>
#import "MJExtension.h"
#import "SortStatus.h"
#import "AppDelegate.h"
//#import <CommonCrypto/CommonDigest.h>

@interface LivingController ()<UIImagePickerControllerDelegate,UIActionSheetDelegate,UIScrollViewDelegate,UITextViewDelegate>

@property (strong,nonatomic) AVCaptureSession *captureSession;//负责输入和输出设备之间的数据传递
@property (strong,nonatomic) AVCaptureDeviceInput *captureDeviceInput;//负责从AVCaptureDevice获得输入数据
@property (strong,nonatomic) AVCaptureStillImageOutput *captureStillImageOutput;//照片输出流
@property (strong,nonatomic) AVCaptureVideoPreviewLayer *captureVideoPreviewLayer;//相机拍摄预览图层
@property (strong ,nonatomic)UIImageView *videoView;
@property (weak ,nonatomic)JsTextView *activityNameTF;
@property (weak ,nonatomic)JsTextView *activityNameTF1;
@property (weak ,nonatomic)UITextField *activityNameTF2;
@property (weak ,nonatomic)UITextField *activityNameTF3;
@property (weak ,nonatomic)UITextField *activityNameTF4;
@property (strong ,nonatomic)UIButton *setFMBtn;
@property (strong ,nonatomic)UILabel *SetLb;
@property (nonatomic ,weak)UIView *MenuView;
@property (strong ,nonatomic)UIView *backView2;
@property (strong ,nonatomic)UIView *backView3;
@property (strong ,nonatomic)UIView *backView4;
@property (strong ,nonatomic)UIScrollView *bigView;
@property (weak ,nonatomic)UIImage *image;
@property (strong ,nonatomic)NSMutableArray *sortPlayArray;
@property (copy ,nonatomic)NSString *numberID;
@property (assign ,nonatomic)NSString *activityId;
@property (copy ,nonatomic)NSString *imageName;
@property (copy ,nonatomic)NSString *uuidStr;
@property (copy ,nonatomic)NSString *zhiBoID;
@property (assign, nonatomic)NSInteger FenBianLv;
@property (weak ,nonatomic)UILabel *pepoleCountLb;
@property (strong ,nonatomic)NSTimer *timer;
@property (copy, nonatomic)NSString *orientationScreenTag;
@property (assign, nonatomic)NSInteger orientationScreen;

//@property (co, nonatomic)NSInteger origentStr;

@end

@implementation LivingController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self makeUI];
    self.FenBianLv = 4;
//    [self loadCatoryData];
    
}

- (void)loadPepoleCount{
    
    NSUserDefaults *activityIdDefaults = [NSUserDefaults standardUserDefaults];
    NSString *activityID = [activityIdDefaults objectForKey:@"activty_id"];
    NSLog(@"%@",activityID);
   NSThread *thred = [NSThread currentThread];
    NSLog(@"%@",thred);
    NSDictionary *params = @{@"activityId":activityID};
    [HttpTool postWithURL:@"http://sdk2.karat.tv:8081/activity/onlineVeiwers?" params:params success:^(id json) {
        
        NSString *str = json[@"payload"];
        NSLog(@"%@",str);
        NSString *pepoleCountStr = [NSString stringWithFormat:@" %@人在线",str];
        self.pepoleCountLb.text = pepoleCountStr;
        
    } failure:^(NSError *error) {
        
        
    }];
    
}
- (void)
loadCatoryData{

          NSDictionary *parameters = @{@"classification_id":@"3"};
        [HttpTool postWithURL:@"http://61.135.176.43:6080/bigtobig/sort/search.json?" params:parameters success:^(id json) {
            
            NSLog(@"%@",json);
            NSData *data = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:nil];
            NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
            
            NSLog(@"%@",dict);
            
            NSArray *array = dict[@"sort"];
            
            NSLog(@"%@",array);
            
            
            NSMutableArray *sortPlayArray = [NSMutableArray array];
            if (array == nil) {
                
                return ;
            }
            //遍历返回的数组
            for (int i = 0; i < array.count; i++) {
                
                NSMutableDictionary *dict = array[i];
                NSLog(@"%@",dict);
                
                //字典转模型
                SortStatus *SortPlayModel = [SortStatus SortStatusWithDict:dict];
                
                [sortPlayArray addObject:SortPlayModel];
                
                NSLog(@"%@%@",sortPlayArray,SortPlayModel.sort);
                
            }
            self.sortPlayArray = sortPlayArray;
            NSLog(@"%@",sortPlayArray);
            
            
        } failure:^(NSError *error) {
            
            
        }];
    

}
- (void)load{

    NSUserDefaults *userIdDefault = [NSUserDefaults standardUserDefaults];
    NSString *userID = [userIdDefault objectForKey:@"userID"];
    
    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    
    NSString *dateString = [dateFormatter stringFromDate:currentDate];
    
    NSLog(@"%@",userID);

    NSString *str = [NSString stringWithFormat:@"http://61.135.176.43:6080/bigtobig/live/update.json?id=%@&end_time=%@",userID,dateString];
    
    NSString *urlstr = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSURL *urlstr1 = [NSURL URLWithString:urlstr];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlstr1];
       
    [request setValue:@"application/json,text/json,text/javascript,text/html" forHTTPHeaderField:@"Content-Type"];
    NSLog(@"%@",urlstr);
    // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        NSString *str = dict[@"return_code"];
        NSLog(@"%@",str);
        NSLog(@"%@",dict);
        
        
    }];
}


//获取uuid
- (void)loadData{

    [HttpTool postWithURL:@"http://61.135.176.43:6080/picture/picture/get_uuid.json" params:nil success:^(id json) {
        
        NSLog(@"%@",json);
        
        NSString *uuidStr = json[@"uuid"];
        self.uuidStr = uuidStr;
        NSLog(@"%@",self.uuidStr);
        
    } failure:^(NSError *error) {
        
        
    }];
}
- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
    
}
//- (void)setBackBar{
//    
//
//    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(kScreenWidth - 50, 0, 50, 44)];
//    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [btn setTitle:@"相册" forState:UIControlStateNormal];
//    [btn addTarget:self action:@selector(photo) forControlEvents:UIControlEventTouchUpInside];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
//    
//}


- (void)makeUI{

    UIScrollView *bigView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
    bigView.showsVerticalScrollIndicator = NO;
    
    bigView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    self.bigView = bigView;
    bigView.contentSize = CGSizeMake(0, kScreenHeight +110);
    [self.navigationController.view addSubview:bigView];
    
    bigView.backgroundColor = COLOR_RGBA(236, 235, 232, 1);
    
    UIImageView *VideoView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 200)];
    VideoView.image = [UIImage imageNamed:@"videoView"];
    VideoView.backgroundColor = [UIColor blackColor];
    self.videoView = VideoView;
    VideoView.userInteractionEnabled = YES;
    [self addViewOnVideoView:VideoView];

    [bigView addSubview:VideoView];
    
    
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, VideoView.maxY, kScreenWidth, 45)];
    backView.backgroundColor = [UIColor whiteColor];
    [bigView addSubview:backView];
    
    
    JsTextView *activityNameTF = [[JsTextView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 45)];
    activityNameTF.delegate = self;
    [self.view addSubview:activityNameTF];
    //1.设置提醒文字
    activityNameTF.myPlaceholder=@"  输入活动名称";
    //2.设置提醒文字颜色
    activityNameTF.myPlaceholderColor= [UIColor lightGrayColor];
    activityNameTF.textAlignment = NSTextAlignmentLeft;
    self.activityNameTF = activityNameTF;
    [backView addSubview:activityNameTF];
    
    
    UIView *backView1 = [[UIView alloc]initWithFrame:CGRectMake(0, backView.maxY +10, kScreenWidth, 80)];
    backView1.backgroundColor = [UIColor whiteColor];
    [bigView addSubview:backView1];
    
    
    JsTextView *activityNameTF1 = [[JsTextView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 80)];
    self.activityNameTF1 = activityNameTF1;
    activityNameTF1.delegate = self;
    [self.view addSubview:activityNameTF1];
    //1.设置提醒文字
    activityNameTF1.myPlaceholder=@"  输入活动内容";
    
    //2.设置提醒文字颜色
    activityNameTF1.myPlaceholderColor= [UIColor lightGrayColor];
    activityNameTF1.textAlignment = NSTextAlignmentLeft;
    [backView1 addSubview:activityNameTF1];
    
    
    UIView *backView2 = [[UIView alloc]initWithFrame:CGRectMake(0, backView1.maxY +10, kScreenWidth, 45)];
    backView2.backgroundColor = [UIColor whiteColor];
    self.backView2 = backView2;
    [bigView addSubview:backView2];
    
    UITextField *activityNameTF2 = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 45)];
    activityNameTF2.placeholder = @"  直播分类";
    activityNameTF2.textAlignment = NSTextAlignmentLeft;
    self.activityNameTF2 = activityNameTF2;
    activityNameTF2.userInteractionEnabled = NO;
    self.activityNameTF2.textColor = [UIColor lightGrayColor];
    [backView2 addSubview:activityNameTF2];
    
    UIButton *pullBtn = [[UIButton alloc]initWithFrame:CGRectMake(kScreenWidth - 300, 0, 300, 45)];
    [pullBtn addTarget:self action:@selector(PullButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(300 - 45, 16, 13, 8)];
    imageView.image = [UIImage imageNamed:@"xl"];
    [pullBtn addSubview:imageView];
    [backView2 addSubview:pullBtn];
    
    
    UIView *backView3 = [[UIView alloc]initWithFrame:CGRectMake(0, backView2.maxY +10, kScreenWidth, 45)];
    backView3.backgroundColor = [UIColor whiteColor];
    self.backView3 = backView3;
    [bigView addSubview:backView3];
    
    UITextField *activityNameTF3 = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 45)];
    activityNameTF3.placeholder = @"  分辨率";
    activityNameTF3.textAlignment = NSTextAlignmentLeft;
    self.activityNameTF3 = activityNameTF3;
    activityNameTF3.userInteractionEnabled = NO;
    self.activityNameTF3.textColor = [UIColor lightGrayColor];
    [backView3 addSubview:activityNameTF3];
    
    UIButton *pullBtn1 = [[UIButton alloc]initWithFrame:CGRectMake(kScreenWidth - 300, 0, 300, 45)];
    [pullBtn1 addTarget:self action:@selector(PullButtonClick1:) forControlEvents:UIControlEventTouchUpInside];
    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(300 - 45, 16, 13, 8)];
    imageView1.image = [UIImage imageNamed:@"xl"];
    
    [pullBtn1 addSubview:imageView1];
    [backView3 addSubview:pullBtn1];
    
    
    UIView *backView4 = [[UIView alloc]initWithFrame:CGRectMake(0, backView3.maxY +10, kScreenWidth, 45)];
    backView4.backgroundColor = [UIColor whiteColor];
    self.backView4 = backView4;
    [bigView addSubview:backView4];
    
    UITextField *activityNameTF4 = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 45)];
    activityNameTF4.placeholder = @"  屏幕样式";
    activityNameTF4.textAlignment = NSTextAlignmentLeft;
    self.activityNameTF4 = activityNameTF4;
    activityNameTF4.userInteractionEnabled = NO;
    self.activityNameTF4.textColor = [UIColor lightGrayColor];
    [backView4 addSubview:activityNameTF4];
    
    UIButton *pullBtn2 = [[UIButton alloc]initWithFrame:CGRectMake(kScreenWidth - 300, 0, 300, 45)];
    [pullBtn2 addTarget:self action:@selector(PullButtonClick2:) forControlEvents:UIControlEventTouchUpInside];
    UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(300 - 45, 16, 13, 8)];
    imageView2.image = [UIImage imageNamed:@"xl"];
    
    [pullBtn2 addSubview:imageView2];
    [backView4 addSubview:pullBtn2];
    
    
    UIButton *playBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, backView4.maxY + 10, kScreenWidth - 20, 45)];
    [playBtn setTitle:@"发起直播" forState:UIControlStateNormal];
    [playBtn addTarget:self action:@selector(playVideo) forControlEvents:UIControlEventTouchUpInside];
    playBtn.backgroundColor = COLOR_RGBA(71, 145, 255, 1);
    playBtn.layer.cornerRadius = 5;
    playBtn.layer.masksToBounds = YES;
    [bigView addSubview:playBtn];

    UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 30)];
    [topView setBarStyle:UIBarStyleDefault];
    
    UIBarButtonItem * CancellButton = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(CancellKeyBoard)];

    
    UIBarButtonItem * btnSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    
    UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:self action:@selector(dismissKeyBoard)];
    
    
    NSArray * buttonsArray = [NSArray arrayWithObjects:CancellButton,btnSpace,doneButton,nil];
    
    [topView setItems:buttonsArray];
    [activityNameTF setInputAccessoryView:topView];
    [activityNameTF1 setInputAccessoryView:topView];
    

}
/*
- (void)createFrontCamare{
    
    _captureSession=[[AVCaptureSession alloc]init];
    
    if ([_captureSession canSetSessionPreset:AVCaptureSessionPreset352x288]) {//设置分辨率
        _captureSession.sessionPreset=AVCaptureSessionPreset352x288;
    }
    //获得输入设备
    AVCaptureDevice *captureDevice=[self getCameraDeviceWithPosition:AVCaptureDevicePositionBack];//取得前置摄像头AVCaptureDevicePositionFont
    if (!captureDevice) {
        NSLog(@"取得后置摄像头时出现问题.");
        return;
    }
    
    NSError *error=nil;
    //根据输入设备初始化设备输入对象，用于获得输入数据
    _captureDeviceInput=[[AVCaptureDeviceInput alloc]initWithDevice:captureDevice error:&error];
    if (error) {
        NSLog(@"取得设备输入对象时出错，错误原因：%@",error.localizedDescription);
        return;
    }
    //初始化设备输出对象，用于获得输出数据
    _captureStillImageOutput=[[AVCaptureStillImageOutput alloc]init];
    NSDictionary *outputSettings = @{AVVideoCodecKey:AVVideoCodecJPEG};
    [_captureStillImageOutput setOutputSettings:outputSettings];//输出设置
    
    //将设备输入添加到会话中
    if ([_captureSession canAddInput:_captureDeviceInput]) {
        [_captureSession addInput:_captureDeviceInput];
    }
    
    //将设备输出添加到会话中
    if ([_captureSession canAddOutput:_captureStillImageOutput]) {
        [_captureSession addOutput:_captureStillImageOutput];
    }
    
    //创建视频预览层，用于实时展示摄像头状态
    _captureVideoPreviewLayer=[[AVCaptureVideoPreviewLayer alloc]initWithSession:self.captureSession];
    
    
    CALayer *layer=self.videoView.layer;
    layer.masksToBounds=YES;
    
    _captureVideoPreviewLayer.frame=layer.bounds;
    _captureVideoPreviewLayer.videoGravity=AVLayerVideoGravityResizeAspectFill;//填充模式
    
    //将视频预览层添加到界面中
    [layer addSublayer:_captureVideoPreviewLayer];
    [self addViewOnVideoView:layer];

//    [self.captureSession startRunning];
    
}
*/
/**
 *  取得指定位置的摄像头
 *
 *  @param position 摄像头位置
 *
 *  @return 摄像头设备
 */
-(AVCaptureDevice *)getCameraDeviceWithPosition:(AVCaptureDevicePosition )position{
    NSArray *cameras= [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    for (AVCaptureDevice *camera in cameras) {
        if ([camera position]==position) {
            return camera;
        }
    }
    return nil;
}

- (void)changeIcon
{
    UIAlertController *alertController;
    
    __block NSUInteger blockSourceType = 0;
    
    // 判断是否支持相机因为模拟器不支持相机所以在模拟器上不会有相机这个选项
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        //支持访问相机与相册情况
        alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        
        [alertController addAction:[UIAlertAction actionWithTitle:@"从相册中选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            NSLog(@"点击从相册中选取");
            //相册
            //            blockSourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
            
            imagePickerController.delegate = self;
            
            imagePickerController.allowsEditing = YES;
            
            imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            
            [self presentViewController:imagePickerController animated:YES completion:nil];
        }]];
        
        [alertController addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            NSLog(@"点击拍照");
            
            //相机
            
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
            
            imagePickerController.delegate = self;
            
            imagePickerController.allowsEditing = YES;
            
            imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
            
            [self presentViewController:imagePickerController animated:YES completion:nil];
   
            
        }]];
        
        [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
            NSLog(@"点击取消");
            // 取消
            return;
        }]];
        
        [self presentViewController:alertController animated:YES completion:nil];
    }
    else
    {
        //只支持访问相册情况
        alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        
        [alertController addAction:[UIAlertAction actionWithTitle:@"从相册中选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            NSLog(@"点击从相册中选取");
            //相册
            blockSourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
            
            imagePickerController.delegate = self;
            
            imagePickerController.allowsEditing = YES;
            
            imagePickerController.sourceType = blockSourceType;
            
            [self presentViewController:imagePickerController animated:YES completion:^{
                
            }];
        }]];
        
        [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
            NSLog(@"点击取消");
            // 取消
            return;
        }]];
        
        [self presentViewController:alertController animated:YES completion:nil];
    }
}

#pragma mark - 选择图片后,回调选择

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    
    
    
    /* 此处info 有六个可选类型
     * UIImagePickerControllerMediaType; // an NSString UTTypeImage)
     * UIImagePickerControllerOriginalImage;  // a UIImage 原始图片
     * UIImagePickerControllerEditedImage;    // a UIImage 裁剪后图片
     * UIImagePickerControllerCropRect;       // an NSValue (CGRect)
     * UIImagePickerControllerMediaURL;       // an NSURL
     * UIImagePickerControllerReferenceURL    // an NSURL that references an asset in the AssetsLibrary framework
     * UIImagePickerControllerMediaMetadata    // an NSDictionary containing metadata from a captured photo
     */
    NSLog(@"%@",image);
    
    
    self.SetLb.textColor = [UIColor clearColor];
    [self.setFMBtn setImage:image forState:UIControlStateNormal];
//
    [self saveImage:image];
}
- (NSString *)md5HexDigest:(NSString*)password
{
    
    const char *original_str = [password UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5(original_str, strlen(original_str), result);
    NSMutableString *hash = [NSMutableString string];
    for (int i = 0; i < 16; i++)
    {
        [hash appendFormat:@"%02X", result[i]];
    }
    NSString *mdfiveString = [hash lowercaseString];
    
    NSLog(@"Encryption Result = %@",mdfiveString);
    return mdfiveString;
}

- (void)saveImage:(UIImage *)currentImage
{
    
    Reachability *reach = [Reachability reachabilityForInternetConnection];
    NetworkStatus status = [reach currentReachabilityStatus];
    if (status == NotReachable) {
        
        return;
        
    }

    if (self.uuidStr == nil) {
        
        return;
    }
    NSString *str = [self md5HexDigest:self.uuidStr];

    NSString *b = [str substringWithRange:NSMakeRange(8,16)];
    NSString *str1 = @".png";
    NSString *imgName = [NSString stringWithFormat:@"%@%@",b,str1];
    NSLog(@"%@",imgName);
    NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.8);
    //将设置封面的图片上传到服务器
    [[AFHTTPSessionManager manager] POST:@"http://61.135.176.43:6080/picture/picture/front_cover.json" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        
        [formData appendPartWithFileData:imageData name:@"userfile" fileName:imgName mimeType:@"image/png"];
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSLog(@"%@",responseObject);
        NSMutableArray *array = responseObject[@"upload"];
        for (int i = 0; i<array.count; i++) {
            
            NSDictionary *dict = array[i];
            NSString *str = dict[@"name"];
            NSLog(@"%@",str);
            self.imageName = str;

        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
    }];
    
}

- (void)addViewOnVideoView:(UIImageView *)videoView{
    
    
    UIButton *setFMBtn = [[UIButton alloc]initWithFrame:CGRectMake((self.videoView.bounds.size.width- 107)/2, (self.videoView.bounds.size.height - 83)/2, 107, 83)];
    setFMBtn.backgroundColor = [UIColor clearColor];
    self.setFMBtn = setFMBtn;
    [setFMBtn setImage:[UIImage imageNamed:@"xk"] forState:UIControlStateNormal];
    [setFMBtn addTarget:self action:@selector(setFengMian) forControlEvents:UIControlEventTouchUpInside];

    
    UILabel *SetLb = [[UILabel alloc]initWithFrame:CGRectMake(0,0,setFMBtn.bounds.size.width,setFMBtn.bounds.size.height)];
    SetLb.text = @"设置封面";
    SetLb.textColor = [UIColor whiteColor];
    SetLb.textAlignment = NSTextAlignmentCenter;
    self.SetLb = SetLb;
    
    [setFMBtn addSubview:SetLb];
    [videoView addSubview:setFMBtn];
    [self.videoView addSubview:setFMBtn];

    
}

- (void)PullButtonClick1:(UIButton *)pullBtn{
    
    pullBtn.selected = !pullBtn.selected;
    
    if (pullBtn.selected == YES) {
        
        
        [UIView animateWithDuration:0.5 animations:^{
            
            self.bigView.contentOffset = CGPointMake(0, 216-kScreenHeight+self.activityNameTF.maxY+194+200);
            
        }];
        UIView *menuView = [[UIView alloc]initWithFrame:CGRectMake(0, self.backView3.maxY, kScreenWidth, 150)];
        menuView.backgroundColor = [UIColor whiteColor];
        menuView.userInteractionEnabled = YES;
        self.MenuView = menuView;
        [self.bigView addSubview:menuView];
        
        for (int i = 0; i < 4; i++) {
            
            UIButton *Btn = [[UIButton alloc]initWithFrame:CGRectMake(0, i *40, kScreenWidth, 30)];
            
            Btn.titleLabel.font = [UIFont systemFontOfSize:13.0];
            [menuView addSubview:Btn];
            [Btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [Btn addTarget:self action:@selector(BtnClick1:) forControlEvents:UIControlEventTouchUpInside];
            
            UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, Btn.maxY, kScreenWidth, 0.5)];
            lineView.backgroundColor = COLOR_RGBA(236, 235, 232, 1);
            [menuView addSubview:lineView];
            
            
            if (i == 0) {
                
                [Btn setTitle:@"高清" forState:UIControlStateNormal];
                Btn.tag = 0;
                
            }if (i == 1) {
                
                [Btn setTitle:@"标清" forState:UIControlStateNormal];
                Btn.tag = 1;
                
            }if (i == 2) {
                
                [Btn setTitle:@"普清" forState:UIControlStateNormal];
                Btn.tag = 2;
                
            }if (i == 3) {
                
                [Btn setTitle:@"流畅" forState:UIControlStateNormal];
                Btn.tag = 3;
            }
            
            
        }
        
    }else{
        
        [self.MenuView removeFromSuperview];
        
    }

    
}
- (void)PullButtonClick:(UIButton *)pullBtn{
    
        pullBtn.selected = !pullBtn.selected;
        
        if (pullBtn.selected == YES) {
            
            
            [UIView animateWithDuration:0.5 animations:^{
                
                self.bigView.contentOffset = CGPointMake(0, 216-kScreenHeight+self.activityNameTF.maxY+164+50+180+30);
                
            }];
            UIView *menuView = [[UIView alloc]initWithFrame:CGRectMake(0, self.backView2.maxY, kScreenWidth, 231)];
            menuView.backgroundColor = [UIColor whiteColor];
            menuView.userInteractionEnabled = YES;
            self.MenuView = menuView;
            [self.bigView addSubview:menuView];
            
            for (int i = 0; i < 6; i++) {
                
                UIButton *Btn = [[UIButton alloc]initWithFrame:CGRectMake(0, i *40, kScreenWidth, 30)];
                
                Btn.titleLabel.font = [UIFont systemFontOfSize:13.0];
                [menuView addSubview:Btn];
                [Btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [Btn addTarget:self action:@selector(BtnClick:) forControlEvents:UIControlEventTouchUpInside];
                
                UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, Btn.maxY, kScreenWidth, 0.5)];
                lineView.backgroundColor = COLOR_RGBA(236, 235, 232, 1);
                [menuView addSubview:lineView];
                
                
                SortStatus *sortPlay = self.sortPlayArray[i];
                if (i == 0) {
                    
                    NSLog(@"%@",sortPlay.sort);
//                    [Btn setTitle:sortPlay.sort forState:UIControlStateNormal];
                    [Btn setTitle:@"金融" forState:UIControlStateNormal];
//                    Btn.tag = [sortPlay.userid intValue];
                    Btn.tag = 21;
                    
                }if (i == 1) {
                    
//                    [Btn setTitle:sortPlay.sort forState:UIControlStateNormal];
                    [Btn setTitle:@"互联网" forState:UIControlStateNormal];
                    Btn.tag = 22;
                    NSLog(@"%@",sortPlay.sort);
//                    Btn.tag = [sortPlay.userid intValue];

                    
                }if (i == 2) {
                    
//                    [Btn setTitle:sortPlay.sort forState:UIControlStateNormal];
                    [Btn setTitle:@"汽车" forState:UIControlStateNormal];
                    Btn.tag = 23;
//                    Btn.tag = [sortPlay.userid intValue];

                }if (i == 3) {
                    
//                    [Btn setTitle:sortPlay.sort forState:UIControlStateNormal];
                    [Btn setTitle:@"教育" forState:UIControlStateNormal];
                    Btn.tag = 24;
//                    Btn.tag = [sortPlay.userid intValue];

                }if (i == 4) {
                    
//                    [Btn setTitle:sortPlay.sort forState:UIControlStateNormal];
                    [Btn setTitle:@"健康" forState:UIControlStateNormal];
                    Btn.tag = 25;
//                    Btn.tag = [sortPlay.userid intValue];

                }if (i == 5) {
                    
//                    [Btn setTitle:sortPlay.sort forState:UIControlStateNormal];
                    [Btn setTitle:@"其他" forState:UIControlStateNormal];
                    Btn.tag = 26;
//                    Btn.tag = [sortPlay.userid intValue];

                }
                
                
            }
            
        }else{
            
            [self.MenuView removeFromSuperview];
            
        }

   
}

- (void)PullButtonClick2:(UIButton *)pullBtn{
    
    pullBtn.selected = !pullBtn.selected;
    
    if (pullBtn.selected == YES) {
        
        
        [UIView animateWithDuration:0.5 animations:^{
            
            self.bigView.contentOffset = CGPointMake(0, 216-kScreenHeight+self.activityNameTF.maxY+170+200);
            
        }];
        UIView *menuView = [[UIView alloc]initWithFrame:CGRectMake(0, self.backView4.maxY, kScreenWidth, 72)];
        menuView.backgroundColor = [UIColor whiteColor];
        menuView.userInteractionEnabled = YES;
        self.MenuView = menuView;
        [self.bigView addSubview:menuView];
        
        for (int i = 0; i < 2; i++) {
            
            UIButton *Btn = [[UIButton alloc]initWithFrame:CGRectMake(0, i *40, kScreenWidth, 30)];
            
            Btn.titleLabel.font = [UIFont systemFontOfSize:13.0];
            [menuView addSubview:Btn];
            [Btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [Btn addTarget:self action:@selector(BtnClick2:) forControlEvents:UIControlEventTouchUpInside];
            
            UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, Btn.maxY, kScreenWidth, 0.5)];
            lineView.backgroundColor = COLOR_RGBA(236, 235, 232, 1);
            [menuView addSubview:lineView];
            
            
            if (i == 0) {
                
                [Btn setTitle:@"竖屏直播" forState:UIControlStateNormal];
                Btn.tag = 0;
                
            }if (i == 1) {
                
                [Btn setTitle:@"横屏直播" forState:UIControlStateNormal];
                Btn.tag = 1;
                
                
            }

            
        }
        
    }else{
        
        [self.MenuView removeFromSuperview];
        
    }
    
    
}

- (void)BtnClick:(UIButton *)btn{

    
    [UIView animateWithDuration:0.5 animations:^{
        
        self.bigView.contentOffset = CGPointMake(0, 60);
        
    }];
    NSString *str1 = [NSString stringWithFormat:@"%ld",(long)btn.tag];
    self.numberID = str1;
    NSLog(@"%@",self.numberID);
    NSString *str = [NSString stringWithFormat:@"   %@",btn.titleLabel.text];
    self.activityNameTF2.text = str;
    [self.MenuView removeFromSuperview];
}

- (void)BtnClick1:(UIButton *)btn{
    
    
    [UIView animateWithDuration:0.5 animations:^{
        
        self.bigView.contentOffset = CGPointMake(0, 60);
        
    }];
    
    if (btn.tag == 0) {
        self.FenBianLv = VideoQualityVeryHigh;

    }if (btn.tag == 1) {
        self.FenBianLv = VideoQualityHigh;

    }if (btn.tag == 2) {
        self.FenBianLv = VideoQualityNormal;
        
    }if (btn.tag == 3) {
        self.FenBianLv = VideoQualityLow;

    }
    NSString *str = [NSString stringWithFormat:@"   %@",btn.titleLabel.text];
    NSLog(@"%@",str);
    self.activityNameTF3.text = str;

    [self.MenuView removeFromSuperview];
}

- (void)BtnClick2:(UIButton *)btn{
    
    
    
    [UIView animateWithDuration:0.5 animations:^{
        
        self.bigView.contentOffset = CGPointMake(0, 110);
        
    }];
    
    if (btn.tag == 0) {
        
        self.orientationScreen = ScreenTypeVertical;
        self.orientationScreenTag = [NSString stringWithFormat:@"%ld",btn.tag];
    }if (btn.tag == 1) {
        
        self.orientationScreen = ScreenTypeCross;
        self.orientationScreenTag = [NSString stringWithFormat:@"%ld",btn.tag];
    }

    NSString *str = [NSString stringWithFormat:@"   %@",btn.titleLabel.text];
    NSLog(@"%@",str);
    self.activityNameTF4.text = str;
    
    [self.MenuView removeFromSuperview];
}

- (void)playVideo{
    
    NSLog(@"111%@",self.activityNameTF.text);
    

    if (self.imageName.length == 0) {
        
        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
        HUD.labelText = @"请设置封面";
        HUD.mode = MBProgressHUDModeText;
        [HUD hide:YES afterDelay:1.0];
        
        
    }else if (self.activityNameTF.text.length == 0) {
        
        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
        HUD.labelText = @"请填写活动名称";
        HUD.mode = MBProgressHUDModeText;
        [HUD hide:YES afterDelay:1.0];

    }else if (self.activityNameTF1.text.length == 0){
    
        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
        HUD.labelText = @"请填写活动内容";
        HUD.mode = MBProgressHUDModeText;
        [HUD hide:YES afterDelay:1.0];
        
    }else if(self.numberID == nil) {
        
        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
        HUD.labelText = @"请填写直播分类";
        HUD.mode = MBProgressHUDModeText;
        [HUD hide:YES afterDelay:1.0];
    
    }else if(!(self.FenBianLv == 0||self.FenBianLv==1||self.FenBianLv==2||self.FenBianLv==3)){
    
        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
        HUD.labelText = @"请填写分辨率";
        HUD.mode = MBProgressHUDModeText;
        [HUD hide:YES afterDelay:1.0];
        
    }else if(!(self.orientationScreen == 0||self.orientationScreen==1)){
        
        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
        HUD.labelText = @"请填写录播方向";
        HUD.mode = MBProgressHUDModeText;
        [HUD hide:YES afterDelay:1.0];
        
    }else{

        NSUserDefaults *sdkLoginName = [NSUserDefaults standardUserDefaults];
        NSString *loginName = [sdkLoginName objectForKey:@"loginName"];

        NSUserDefaults *sdkLoginSecreate = [NSUserDefaults standardUserDefaults];
        NSString *LoginSecreate = [sdkLoginSecreate objectForKey:@"Secreate"];
        NSLog(@"%@",loginName);
        NSLog(@"%@",LoginSecreate);

        NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
        NSString *UID = [userID objectForKey:@"userID"];
        
            NSUserDefaults *lineNameDefaults = [NSUserDefaults standardUserDefaults];
        NSString *lineName = [lineNameDefaults objectForKey:@"name"];
        
        NSLog(@"%@",loginName);
        NSLog(@"%@",LoginSecreate);
        NSLog(@"%@",UID);
        
    [AVCamViewController getLoginUserInfo:loginName withPassword:LoginSecreate withBlock:^(NSString *code, NSInteger activityId, NSInteger userId, NSString *tokenId) {
        
        
        if ([code isEqualToString:@"0"])
        {
            self.avc =[[AVCamViewController alloc] initWithAid:activityId withUserId:userId withType:VideoRecodeHardEncode withQuality:self.FenBianLv withSize:VideoSize1280x720 withToken:tokenId withScreenType:self.orientationScreen ];

            self.avc.delegate = self;
        
            self.activityId = [NSString stringWithFormat:@"%ld",(long)activityId];

            NSLog(@"%@",self.orientationScreenTag);
            NSLog(@"44444444%@",self.activityId);
            NSDictionary *parameters = @{@"uid":UID,@"theme":self.activityNameTF.text,@"front_cover":self.imageName,@"introduction":self.activityNameTF1.text,@"category":self.numberID,@"site_id":@"0",@"transform":self.orientationScreenTag,@"active_id":self.activityId};
        

            [HttpTool postWithURL:@"http://61.135.176.43:6080/bigtobig/live/create.json?" params:parameters success:^(id json) {
                
                NSLog(@"%@",[NSThread currentThread]);
                
                NSLog(@"%@",json);
                
                NSData *data = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:nil];
                NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
                
                NSLog(@"1111111%@",dict);
                
                NSString *zhiBoID = dict[@"id"];
                
                self.zhiBoID = zhiBoID;
                
                NSUserDefaults *zhiBoUser = [NSUserDefaults standardUserDefaults];
                [zhiBoUser setObject:self.zhiBoID forKey:@"zhiboID"];
                [zhiBoUser synchronize];
                
      
                
            } failure:^(NSError *error) {
                
                NSLog(@"%@",error);
                
                 dispatch_async(dispatch_get_main_queue(), ^{
                     
                     MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
                     HUD.labelText = @"网络链接失败";
                     HUD.mode = MBProgressHUDModeText;
                     [HUD hide:YES afterDelay:1.0];
                     
                 });
                
              
            }];
            NSLog(@"%@",[NSThread currentThread]);

            dispatch_async(dispatch_get_main_queue(), ^{

                AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
                appDelegate.allowRotation = 1;
                
                [self presentViewController:self.avc animated:YES completion:^{
                    
//                    AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
//                    appDelegate.allowRotation = 1;
//                    self.view.hidden = YES;
                }];
                UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(30, 30, 126, 36)];
                imageView.image = [UIImage imageNamed:@"zhibobg"];
                [self.avc.view addSubview:imageView];
                
                UIImageView *headImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 36, 36)];
                headImage.layer.masksToBounds = YES;
                headImage.layer.cornerRadius = 18;

                [imageView addSubview:headImage];
                
                
                UILabel *nameLb = [[UILabel alloc]initWithFrame:CGRectMake(headImage.maxX + 5, 0, 60, 18)];
                nameLb.text = lineName;
                nameLb.textColor = [UIColor whiteColor];
                [imageView addSubview:nameLb];
                
                UILabel *pepoleCountLb = [[UILabel alloc]initWithFrame:CGRectMake(headImage.maxX + 5, 18, 60, 18)];
                pepoleCountLb.font = [UIFont systemFontOfSize:10.0];
                pepoleCountLb.textColor = [UIColor whiteColor];
                pepoleCountLb.text = @"0人在线";
                self.pepoleCountLb = pepoleCountLb;
                [imageView addSubview:self.pepoleCountLb];
                
                
                NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
                NSString *UID = [userID objectForKey:@"userID"];
                NSString *str = [self md5HexDigest:UID];
                NSString *b = [str substringWithRange:NSMakeRange(8,16)];
                NSString *str1 = @".png";
                NSString *imgName = [NSString stringWithFormat:@"%@%@",b,str1];
                NSLog(@"%@",imgName);
                
                
                NSString *HeadImageUrl = [NSString stringWithFormat:@"http://61.135.176.43:6080/data/HeadPortrait/%@",imgName];
                
                NSLog(@"%@",HeadImageUrl);
                
                
                UIImageView *imageView1 = [[UIImageView alloc]init];
                
                [imageView1 sd_setImageWithURL:[NSURL URLWithString:HeadImageUrl] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                    
                    //设置头像图片
                    if (error) {
                        
                        [headImage setImage:[UIImage imageNamed:@"tx"]];
                        
                        return ;
                    }
                    headImage.image = imageView1.image;
                    
                    
                }];
      

            });
            
        }else
        {
       
            dispatch_async(dispatch_get_main_queue(), ^{
                
                MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
                HUD.labelText = @"服务器异常";
                HUD.mode = MBProgressHUDModeText;
                [HUD hide:YES afterDelay:1.0];

                
            });
            

                   }
        
    }];
        
    }


}

//- (void)playVideo{
//
//    [AVCamViewController getLoginUserInfo:@"test005" withPassword:@"123456" withBlock:^(NSString *code, NSInteger activityId, NSInteger userId, NSString *tokenId) {
//        
//        //登陆成功
//        if ([code isEqualToString:@"0"])
//        {
//            
//            NSLog(@"%@",[NSThread currentThread]);
//            
//            self.avc =[[AVCamViewController alloc] initWithAid:activityId withUserId:userId withType:VideoRecodeHardEncode withQuality:VideoQualityVeryHigh withSize:VideoSize1280x720 withToken:tokenId ];
//            self.avc.delegate = self;
//            
//            dispatch_async(dispatch_get_main_queue(), ^{
//                
//                [self presentViewController:self.avc animated:YES completion:^{
//                    
//                }];
//                
//                UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(40, 40, 40, 40)];
//                btn.backgroundColor = [UIColor redColor];
//                [self.avc.view addSubview:btn];
//            });
//            
//        }else
//        {
//            NSLog(@"登陆失败");
//        }
//    }];
//
//
//}
-(void) checkTokenIdResult:(NSString*)code withActivityId:(NSInteger)activityId withUserId:(NSInteger)userId
{
    
    //验证成功
    if([code isEqualToString:@"0"])
    {
        
        
    }else if([code isEqualToString:@"-1"])//验证失败 tokenId不正确
    {

    }else if([code isEqualToString:@"-2"])//验证失败 tokenId失效
    {

        
    }else if ([code isEqualToString:@"-10"])//验证失败 其他错误
    {
        

    }
    
    
}
- (void)endPlay{

    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    
    NSString *dateString = [dateFormatter stringFromDate:currentDate];
    

    NSString *str = [NSString stringWithFormat:@"http://61.135.176.43:6080/bigtobig/live/update.json?id=%@&end_time=%@",self.zhiBoID,dateString];
    
    NSString *urlstr = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSURL *urlstr1 = [NSURL URLWithString:urlstr];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlstr1];
    
    [request setValue:@"application/json,text/json,text/javascript,text/html" forHTTPHeaderField:@"Content-Type"];
    NSLog(@"%@",urlstr);
    // 4.发送请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        NSString *str = dict[@"return_code"];
        NSLog(@"%@",str);
        NSLog(@"%@",dict);
        
        
    }];



}
- (void)startTimer{

    NSTimer *timer = [[NSTimer alloc]init];
    timer =  [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(loadPepoleCount) userInfo:nil repeats:YES];
    self.timer = timer;
    [timer fire];

    [[NSRunLoop currentRunLoop]addTimer:timer forMode:NSDefaultRunLoopMode];
    [[NSRunLoop currentRunLoop]run];
}
- (void)viewWillAppear:(BOOL)animated{

//    AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
//    appDelegate.allowRotation = 0;
    
//    self.view.hidden = NO;
}
- (void)viewWillDisappear:(BOOL)animated{

    [super viewWillDisappear:animated];
    

}

- (void)liveRecordStateChanged:(VideoRecordState)state
{
    NSLog(@"直播状态改变：%u", state);
    
    switch (state) {
            
        case VideoRecordStateStarted:
            NSLog(@"开始直播");
            NSLog(@"");
        {
            

           NSThread *t =  [[NSThread alloc]initWithTarget:self selector:@selector(startTimer) object:nil];
            [t start];
            [self.captureSession stopRunning];

        }

            
            break;
        case VideoRecordStatePaused:
            NSLog(@"暂停直播");
            
            break;
        case VideoRecordStateStoped:
            NSLog(@"结束直播");
        {
            

            [self.timer invalidate];
            [self endPlay];
        }
        
            break;
            
        default:
            break;
    }
}

- (void)recordControllerExited:(NSInteger)activeId
{
    
    AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    appDelegate.allowRotation = 0;
    NSLog(@"活动ID：%ld 退出直播", (long)activeId);
    
}


- (void)setFengMian{

    Reachability *reach = [Reachability reachabilityForInternetConnection];
    NetworkStatus status = [reach currentReachabilityStatus];
    if (status == NotReachable) {
        
        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
        HUD.labelText = @"请链接网络后设置封面";
        HUD.mode = MBProgressHUDModeText;
        [HUD hide:YES afterDelay:1.0];
        
        return;
        
    }
    [self loadData];

    [self changeIcon];

}

//- (void)viewWillAppear:(BOOL)animated{
//
//    [self.captureSession startRunning];
//}

//- (void)viewDidAppear:(BOOL)animated{

//    [self.captureSession startRunning];
//    [self createFrontCamare];

//}
//- (void)viewDidDisappear:(BOOL)animated{



//}


//- (void)viewWillAppear:(BOOL)animated{
//
//    [self.captureSession startRunning];
//
//}

- (void)textViewDidEndEditing:(UITextView *)textView{

    [self.activityNameTF resignFirstResponder];
}


-(void)dismissKeyBoard
{
    [UIView animateWithDuration:0.5 animations:^{
        

    self.bigView.contentOffset = CGPointMake(0, 0);

        
    }];
    
    [self.activityNameTF resignFirstResponder];
    [self.activityNameTF1 resignFirstResponder];
}


- (void)CancellKeyBoard{

    [UIView animateWithDuration:0.5 animations:^{
        

    self.bigView.contentOffset = CGPointMake(0, 0);
        
    }];
    
    [self.activityNameTF resignFirstResponder];
    [self.activityNameTF1 resignFirstResponder];

}
- (void)textViewDidBeginEditing:(UITextView *)textView{
    
    
    if (textView == self.activityNameTF) {
        
        
        [UIView animateWithDuration:0.5 animations:^{
            
            self.bigView.contentOffset = CGPointMake(0, 216-kScreenHeight+self.activityNameTF.maxY+164 + 100+80);
            
        }];
        
    }if (textView == self.activityNameTF1) {
        
        [UIView animateWithDuration:0.5 animations:^{
            
            self.bigView.contentOffset = CGPointMake(0, 216-kScreenHeight+self.activityNameTF.maxY+164+50+180);
            
        }];
    }

}


@end
